package com.zmc.lostfound.search.vo;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * @author zmc
 * @description 分页查询结果解析类
 */
@Data
@NoArgsConstructor
public class SearchResult implements Serializable {

    private static final long serialVersionUID = -3590881354676212089L;

    /**
     * 当前页码
     */
    private Integer pageNo;

    /**
     * 页面大小
     */
    private Integer pageSize;

    /**
     * 总记录数
     */
    private Integer totalCount;

    /**
     * 总页数
     */
    private Integer totalPage;

    /**
     * 查询结果集
     */
    private List<?> dataList;

    /**
     * 分页
     *
     * @param dataList   查询结果集
     * @param pageNo     当前页码
     * @param pageSize   页面大小
     * @param totalCount 总记录数
     */
    public SearchResult(List<?> dataList, int pageNo, int pageSize, int totalCount) {
        this.dataList = dataList;
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.totalPage = (int) Math.ceil((double) totalCount / pageSize);
    }

    /**
     * 计算总页数
     */
    public void calculateTotalPage() {
        if (totalCount <= 0 || pageSize <= 0) {
            return;
        }
        totalPage = (int) Math.ceil(totalCount / (double) pageSize);
    }

}
